package com.seven.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import com.seven.entity.Problem;

//问题dao
public class AProblemDao extends BaseDao{

	/**
	 * 问题的增加
	 */
	public int addProblem(Problem problem) {
		String sql = "insert into problem(problem_title, problem_content, problem_addcontent, problem_time, problem_address, problem_picture, problem_bickunm, problem_picture2, problem_isauditor, problem_ispass, users_id) values(?,?,?,?,?,?,?,?,?,?,?)";
		Object[] ob = {problem.getProblem_title(),problem.getProblem_content(),problem.getProblem_addcontent(),problem.getProblem_time(),problem.getProblem_address(),problem.getProblem_picture(),problem.getProblem_bickunm(),problem.getProblem_picture2(),problem.getProblem_isauditor(),problem.getProblem_ispass(),problem.getUsers_id()};
		return super.update(sql, ob);
		
	}


	
	/**
	 * 问题删除
	 */
	public int deleteProblem(Problem problem) {
		String sql = "delete from problem where problem_id=?";
		int ob = problem.getProblem_id();
		return super.update(sql, ob);
	}
	
	/**
	 * 问题的修改
	 */
	public int updatePromblem(Problem problem) {
		String sql = "update problem set problem_title=?, problem_content=?, problem_addcontent=?, problem_time=?, problem_address=?, problem_picture=?, problem_bickunm=?, problem_picture2=?, problem_isauditor=?, problem_ispass=?, user_id=?, worker_id=? where problem_id =?";
		int ob = problem.getProblem_id();
		return super.update(sql, ob);
		
	}
	
	/**
	 * 修改问题处理
	 */
	public int updatePromblem1(Problem problem) {
		String sql = "update problem set problem_picture2=? where problem_id =?";
		Object[] ob = {problem.getProblem_picture2(),problem.getProblem_id()};
		return super.update(sql, ob);
		
	}
	
	/**
	 * 问题的查询(查询所有)
	 */
	public List<Problem> selectAllProblem() {
		String sql = "select * from problem";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 问题的查询(通过id)
	 */
	public List<Problem> selectByProblem_id(Problem problem) {
		
		String sql = "select * from problem where problem_id=?";
		int ob = problem.getProblem_id();
		return super.query2(sql, Problem.class, ob);
	
	}
	
	/**
	 * 问题查询(通过用户id)
	 */
	public List<Problem> selectByUsers_id(Problem problem) {
		String sql = "select * from problem where users_id=?";
		int ob = problem.getUsers_id();
		return super.query2(sql, Problem.class, ob);
		
	}
	
	/**
	 * 问题查询(通过员工id)
	 */
	public List<Problem> selectByWorker_id(Problem problem) {
		String sql = "select * from problem where worker_id=?";
		int ob = problem.getWorker_id();
		return super.query2(sql, Problem.class, ob);
		
	}

	public static void main(String[] args) {
		ProblemDao problemDao = new ProblemDao();
		Problem problem = new Problem();
		problem.setWorker_id(1);
		List<Problem> problems = problemDao.selectByWorker_id(problem);
		for (Problem problem1 :problems) {
			System.out.println(problem1);
		}

	}




	
	/**
	 * 问题查询(未审核)
	 */
	public List<Problem> selectByproblem_isauditor0() {
		String sql = "select * from problem where problem_isauditor=0";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 问题查询(已审核)
	 */
	public List<Problem> selectByproblem_isauditor1() {
		String sql = "select * from problem where problem_isauditor=1";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 问题查询(已审核,未处理)
	 */
	public List<Problem> selectByproblem_ispass_1() {
		String sql = "select * from problem where problem_ispass=-1";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 问题查询(已审核,处理中)
	 */
	public List<Problem> selectByproblem_ispass0() {
		String sql = "select * from problem where problem_ispass=0";
		return super.query2(sql, Problem.class);
		
	}
	
	/**
	 * 问题查询(已审核,已处理)
	 */
	public List<Problem> selectByproblem_ispass1() {
		String sql = "select * from problem where problem_ispass=1";
		return super.query2(sql, Problem.class);
		
	}
}
